package com.banmoon.algorithm.leetcode;

public class Question11 {

    public static void main(String[] args) {
        int[] ints = {1,8,6,2,5,4,8,3,7};
        System.out.println(maxArea(ints));
        // 记录着他们原来的位置，从高到低，[1, 1]
    }

    public static int maxArea(int[] height) {
        int result = 0;
        for (int i = 0; i < height.length-1; i++) {
            for (int j = i+1; j < height.length; j++) {
                int h = height[i]>height[j]? height[j]: height[i];
                int w = j-i;
                int temp = h*w;
                if(result < temp)
                    result = temp;
            }
        }
        return result;
    }

    public int maxArea1(int[] height) {
        int left = 0;
        int right = height.length-1;
        int temp_area = 0;
        int rst_area = Math.min(height[left], height[right]) * (right-left);

        while(left != right){
            if(height[left]>height[right])
                right--;
            else
                left++;

            temp_area = Math.min(height[left],height[right])*(right-left);
            rst_area = rst_area>temp_area? rst_area: temp_area;
        }

        return rst_area;
    }
}
